package com.py.warehouse.service.impl;

import com.py.warehouse.domain.BsWarehouse;
import com.py.warehouse.domain.BsWhLocation;
import com.py.warehouse.mapper.BsWarehouseMapper;
import com.py.warehouse.mapper.BsWhLocationMapper;
import com.py.warehouse.service.IBsWarehouseService;
import com.py.warehouse.service.IBsWhLocationService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 仓库列表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-25
 */
@Service
public class BsWhLocationServiceImpl implements IBsWhLocationService
{
    @Autowired
    private BsWhLocationMapper bsWhLocationMapper;

    @Override
    public List<BsWhLocation> selectBsWhLocation(BsWhLocation bsWhLocation) {
        return bsWhLocationMapper.selectBsWhLocation(bsWhLocation);
    }

    @Override
    public int deleteBsWhLocationByLocationId(Long locationId) {
        return bsWhLocationMapper.deleteBsWhLocationByLocationId(locationId);
    }

    @Override
    public int deleteBsWhLocationByLocationIds(Long[] locationId) {
        return bsWhLocationMapper.deleteBsWhLocationByLocationIds(locationId);
    }

    @Override
    public int updateBsWhLocation(BsWhLocation bsWhLocation) {
        bsWhLocation.setUpdateBy(SecurityUtils.getUsername());
        bsWhLocation.setUpdateTime(new Date());
        return bsWhLocationMapper.updateBsWhLocation(bsWhLocation);
    }

    @Override
    public int insertBsWhLocation(BsWhLocation bsWhLocation) {
        if (bsWhLocation.getIsDelete() == null || bsWhLocation.getIsDelete().equals("")){
            bsWhLocation.setIsDelete("0");
        }
        if (bsWhLocation.getLocationVessel() == null || bsWhLocation.getLocationVessel().equals("")){
            bsWhLocation.setLocationVessel(BigDecimal.valueOf(100));
        }
        if (bsWhLocation.getManager() == null || bsWhLocation.getManager().equals("")){
            bsWhLocation.setManager("张四");
        }
        if (bsWhLocation.getLocationStatus() == null || bsWhLocation.getLocationStatus().equals("")){
            bsWhLocation.setLocationStatus("0");
        }
        if (bsWhLocation.getLocationSort() == null || bsWhLocation.getLocationSort().equals("")){
            bsWhLocation.setLocationSort(selectBsWhLocationByLocationEnd().getLocationId() + 1);
        }
        bsWhLocation.setCreateBy(SecurityUtils.getUsername());
        bsWhLocation.setCreateTime(new Date());
        System.out.println("库位信息：");
        System.out.println(bsWhLocation);
        return bsWhLocationMapper.insertBsWhLocation(bsWhLocation);
    }

    @Override
    public BsWhLocation selectBsWhLocationByLocationId(Long locationId) {
        return bsWhLocationMapper.selectBsWhLocationByLocationId(locationId);
    }

    @Override
    public BsWhLocation selectBsWhLocationByLocationEnd() {
        return bsWhLocationMapper.selectBsWhLocationByLocationEnd();
    }

    @Override
    public int updateBsWhLocationByWarehouseCodes(Long[] warehouseIds, String warehouseCode) {
        return bsWhLocationMapper.updateBsWhLocationByWarehouseCodes(warehouseIds, warehouseCode);
    }

    @Override
    public Integer selectBsWhLocationByCount(String warehouseCode) {
        return bsWhLocationMapper.selectBsWhLocationByCount(warehouseCode);
    }

    @Override
    public Integer updateDeactivate(String locationCode,String status) {
        return bsWhLocationMapper.updateDeactivate(locationCode,status);
    }

    @Override
    public int updateBsWhLocationDelWarehouseCodes(Long[] warehouseIds, String warehouseCode) {
        return bsWhLocationMapper.updateBsWhLocationDelWarehouseCodes(warehouseIds, warehouseCode);
    }

    @Override
    public Long[] selectWarehouseCode(String warehouseCode) {
        return bsWhLocationMapper.selectWarehouseCode(warehouseCode);
    }

    @Override
    public List<BsWhLocation> selectLocationByWarehouseCode(String warehouseCode) {
        return bsWhLocationMapper.selectLocationByWarehouseCode(warehouseCode);
    }

    @Override
    public int updateRemoveWarehouseCode(String warehouseCode) {
        return bsWhLocationMapper.updateRemoveWarehouseCode(warehouseCode);
    }
}
